﻿@model System.Collections.ArrayList
@{
    ViewBag.Title = "Requistion Detail";
    Layout = "~/Views/Shared/_Layout.cshtml";
    BTKERP.Model.RequisitionMaster master = Model[0] as BTKERP.Model.RequisitionMaster;
    List<BTKERP.Model.RequisitionDetail> details = Model[1] as List<BTKERP.Model.RequisitionDetail>;
}
@{
    ViewBag.Title = "Approve";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section AdditionalJS
{
    <script type="text/javascript">
        function approveMaster() {
            if (confirm("Are you sure to approve?")) {
                $("#actionType").val(1);
                $.post("/Requistion/Approve", $("#detailForm").serialize(), function (data) {
                    if (data && data.Message.length > 0)
                    { alert(data.Message); }
                    window.location.href = window.location.href;
                });
            }
        }

        function rejectMaster() {
            if (confirm("Are you sure to reject?")) {
                $("#actionType").val(2);
                $.post("/Requistion/Approve", $("#detailForm").serialize(), function (data) {
                    if (data && data.Message.length > 0)
                    { alert(data.Message); }
                    window.location.href = window.location.href;
                });
            }
        }
    </script>

}

<h2>Approve/Reject Requisition</h2>
<h5>@Html.ActionLink("Back To Requisition List","Management")</h5>
<table class="editor W800">
    <thead>
        <tr>
            <td class="left" colspan="4">Requision Info</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="right W200">
                Requision From 
            </td>
            <td class="left W300">
                @BTKERP.MVCWeb.AppCode.DataRefHelper.GetWarehouseById(master.FromWarehouseId)
            </td>
             <td class="right W200">
                Requision To 
            </td>
            <td class="left W300">
               @BTKERP.MVCWeb.AppCode.DataRefHelper.GetWarehouseById(master.ToWarehouseId)
                
            </td>
        </tr>
        <tr>
            <td class="right">
                Requision Code
            </td>
            <td class="left">
                @master.RequisitionCode 
            </td>
           <td class="right">
                Delivery Date
            </td>
            <td class="left">
                 @master.DeliveryDate.Value.ToString("MM/dd/yyyy") 
            </td>   
        </tr>
        <tr>
            <td class="right">
                Requision Date
            </td>
            <td class="left">
                @master.RequisitionDate.ToString("MM/dd/yyyy")
            </td>
            <td class="right">
                Requision By
            </td>
            <td class="left">
                @master.RequisitionedBy
            </td>
        </tr>
        <tr>
            <td class="right">
                Fulfilled Date
            </td>
            <td class="left">
                @master.FulfilledDate.ToString("MM/dd/yyyy") 
            </td>
            <td class="right">
                Fulfilled By
            </td>
            <td class="left">
                @master.FulfilledBy
            </td>
        </tr>    
         <tr>
            <td colspan="4" class="center">
                <input type="button" id="btnSave" class="btn btn-blue" value="Approve" onclick="approveMaster();"/>
                <input type="button" id="btnSubmit" class="btn btn-red" value="Reject" onclick="rejectMaster();"/>
            </td>
        </tr>
    </tbody>
</table>
<hr />
<form id="detailForm" name="detailForm" method="post">
<input type="hidden" name="masterId" id="masterId" value="@ViewData["masterId"]" />
<input type="hidden" name="actionType" id="actionType" value="" />
<table id="dt" class="display stylized">
    <tr>
        <th>Item Name</th>
        <th>Push\Pack Units</th>
        <th>Current On Hand</th>
        <th>Quantity Req'd</th>
    </tr>
        @foreach (var detail in details)
        {
            var product = @BTKERP.MVCWeb.AppCode.DataRefHelper.GetProductById(detail.ProductId);
         
    <tr>
        <td>@product.Name</td>   
        <td>
            @BTKERP.MVCWeb.AppCode.DataRefHelper.GetUnitName(detail.UnitId.ToString())
        </td>
        <td>
            @BTKERP.MVCWeb.AppCode.DataRefHelper.GetCurrentStock(product.Id, master.FromWarehouseId)
        </td>
        <td>
          <input type="text" name="number|@detail.ProductId.ToString()" id="number|@detail.ProductId.ToString()" value="@detail.RequestedQty.ToString("N0")" />
        </td>
    </tr>
        }
</table>
</form>